package com.wm.mvp

import java.lang.ref.WeakReference

abstract class BasePresenter<M : BaseModel, V : BaseView> {
    private var wrf: WeakReference<V>? = null
    var model: M? = null

    fun registerModel(model: M) {
        this.model = model
    }

    fun registerView(view: V) {
        wrf = WeakReference(view)
    }

    fun getView(): V? {
        return wrf?.get()
    }

    fun destroy() {
        wrf?.clear()
        wrf = null
        onViewDestroy()
    }

    abstract fun onViewDestroy()
}